import { useUserStore } from '@/store';
import { ref } from 'vue';

export default function useLogin() {
  const userStore = useUserStore();
  const isLoading = ref<boolean>(false);

  const onLogin = async ({
    username,
    password,
    loginType = 'username'
  }: {
    username: string;
    password: string;
    loginType?: 'username';
  }) => {
    isLoading.value = true;
    await userStore.login({
      username,
      password,
      loginType
    });
  };

  return { isLoading, onLogin };
}
